﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using TaskManager.App.Models;

namespace TaskManager.App.Controllers
{
    [Authorize]
    public class HomeController : Controller
    {
        private SystemDbContext _db = new SystemDbContext();

        public HomeController()
        {
            if (!_db.Tasks.Any())
            {
                _db.Tasks.Add(new Task
                    {
                        CreationTime = DateTime.Now,
                        DueDate = DateTime.Now.AddYears(1),
                        Description = "Test task",
                        Originator = _db.Users.First(),
                        AssignedToUsers = new List<User>(_db.Users)
                    });
                _db.SaveChanges();
            }
        }

        public ActionResult Index()
        {
            ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";

            return View();
        }

        public ActionResult About()
        {
            ViewBag.Message = "Your app description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }

        public JsonResult Load()
        {
            return Json(_db.Tasks.First(), JsonRequestBehavior.AllowGet);
        }
    }
}
